<template>
	<view class="equipment">
		<view class="head" :style="{height: pHeight + tHeight + 'px'}">
			<view class="xztitle" :style="[{height: pHeight + 'px', top: tHeight + 'px',lineHeight: pHeight + 'px'}]">
				新增反馈
				<view class="iconfont icon-dayuhao1" @click="fanhui"></view>
			</view>
		</view>
		<view class="headtop" :style="{marginTop: pHeight + tHeight + 'px'}">
			<view class="top clearfix">
				<view class="left fl clearfix">
					<view class="mess fl">
						<view :class="[attrIndex==1?'active':'']" @click="attrIndex = 1">意见反馈</view>
						<text class="dian" v-if="attrIndex == 1"></text>
					</view>
					<view class="mess mess1 fl" @click="attrIndex = 2">
						<view :class="[attrIndex==2?'active':'']">问题反馈</view>
						<text class="dian" v-if="attrIndex == 2"></text>
					</view>
				</view>
			</view>
		</view>
		<view class="form">
			<view class="content contentdx contentlast clearfix">
				<image :src="baseUrl + '/wximage/hktubiao.png'" class="danxuan fl"></image>
				<view class="name fl">反馈标题<text>*</text></view>
			</view>
			<view class="contenttext">
				<textarea placeholder="请输入反馈标题" v-model="title"></textarea>
			</view>
		</view>
		<view class="form form1">
			<view class="content contentdx contentlast clearfix">
				<image :src="baseUrl + '/wximage/hktubiao.png'" class="danxuan fl"></image>
				<view class="name fl">描述内容<text>*</text></view>
			</view>
			<view class="contenttext">
				<textarea placeholder="请输入描述内容" v-model="description"></textarea>
			</view>
		</view>
		<view class="form form1">
			<view class="content contentdx contentlast clearfix">
				<image :src="baseUrl + '/wximage/hktubiao.png'" class="danxuan fl"></image>
				<view class="name fl">请添加图片<text>*</text></view>
			</view>
			<view class="content contenttp contentlast clearfix">
				<image :src="baseUrl + '/wximage/add.png'" class="shangchuan" @click="chooseImage" v-if="image == ''"></image>
				<image :src="image" class="shangchuan" @click="chooseImage" v-else></image>
			</view>
		</view>
		<view class="footer">
			<view class="submit" @click="submit">提交申请</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				baseUrl: getApp().globalData.baseUrl,
				headerTop: 0,
				pHeight: 0,
				tHeight: 0,
				attrIndex: 1,
				title: '',
				description: '',
				image: '',
			}
		},
		onLoad() {
			// 头部距离
			let res = uni.getSystemInfoSync() ///微信api方法
			let titleH;
			if (res && res['system']) {
				// 判断是否是安卓操作系统 （标题栏苹果为44px,安卓为48px）
				if (res['system'].indexOf('Android') > 0) {
					titleH = 48
				} else {
					titleH = 46
				}
				this.headerTop = titleH + res['statusBarHeight']
				this.pHeight = titleH
				this.tHeight = res['statusBarHeight']
			}
		},
		methods: {
			submit() {
				let title = this.title;
				let description = this.description;
				let attrIndex = this.attrIndex;
				let image = this.image;
				
				if(title == '' || description == '' || image == ''){
					uni.showToast({
						title: '信息不能为空',
						icon: 'none'
					})
					return false;
				}
				
				//提交
				this.request({
					url: '/xcx/feedback',
					data: {
						users_id: uni.getStorageSync('agent_id'),
						title: title,
						attr: attrIndex,
						description: description,
						image: image,
					},
					method: "POST"
				}).then(res => {
					if (res.data.code == 200) {
						uni.showToast({
							title: '提交成功,请您耐心等待',
							icon: 'none',
						})
						
						setTimeout(function(){
							uni.navigateBack()
						},2000)
					} else {
						uni.showToast({
							title: '请求失败，请稍后再试',
							icon: 'none'
						})
					}
				})
			},
			chooseImage() {
				let that = this
				uni.chooseImage({
					count: 1,
					sourceType: ['album', 'camera'], // album 从相册选图，camera 使用相机，默认二者都有
					success: function(res) {
						uni.uploadFile({
							url: 'https://aapi.jixiaodian.cn/api/common/cosupdate',
							filePath: res.tempFilePaths[0],
							name: 'file',
							success: function(res1) {
								let arr = JSON.parse(res1.data);
								if(arr.code == 200){
									that.image = arr.data.path;
								}else{
									uni.showToast({
										title: arr.message,
										icon: 'none'
									})
								}
							},
							fail: function(res1) {
								
							},
						})
					}
				})
			},
			fanhui() {
				uni.navigateBack();
			}
		}
	}
</script>

<style lang="scss" scoped>
	.equipment {
		width: 100%;
		margin: 0 auto;
		height: 100vh;
		background: #f9f9ff;
		overflow-y: scroll;

		.head {
			width: 100%;
			position: fixed;
			top: 0;
			left: 0;
			z-index: 99;
			background: linear-gradient(90deg, #f9f9ff, #d4e8ff);

			.xztitle {
				position: fixed;
				left: 0%;
				top: 0;
				width: 100%;
				text-align: left;
				color: #333333;
				font-size: 32rpx;
				padding-left: 74rpx;
				font-weight: 700;

				text {
					font-size: 24rpx;
				}

				.iconfont {
					position: absolute;
					top: 0;
					left: 30rpx;
					font-size: 44rpx;
				}
			}
		}

		.headtop {
			width: 100%;
			background: linear-gradient(90deg, #f9f9ff, #d4e8ff);
			height: 300rpx;
			padding: 20rpx 40rpx 0;
			box-sizing: border-box;

			.top {
				.left {
					.mess {
						height: 48rpx;
						line-height: 48rpx;
						text-align: center;

						view {
							font-size: 24rpx;
							color: #333333;
						}

						.dian {
							width: 8rpx;
							height: 8rpx;
							background: #5C88FA;
							display: block;
							border-radius: 50%;
							margin: 0 auto;
						}

						.active {
							font-size: 32rpx;
							color: #333333;
							font-weight: 700;
							margin-left: 0;
						}
					}

					.mess1 {
						margin-left: 20rpx;
					}
				}

				.right {
					width: 124rpx;
					height: 36rpx;
					line-height: 36rpx;
					text-align: center;
					background: #FFFFFF;
					border-radius: 24rpx;
					margin-top: 6rpx;

					.name {
						font-size: 24rpx;
						color: #333333;
					}
				}
			}
		}

		.form {
			width: 94%;
			margin: 0 auto;
			margin-top: -200rpx;
			background: #FFFFFF;
			border-radius: 20rpx;
			padding: 0 20rpx;
			box-shadow: rgba(223, 230, 255, 0.67) 0px 0px 6px;

			.content {
				height: 92rpx;
				line-height: 92rpx;
				border-bottom: 1rpx solid #D8D8D8;

				.name {
					font-size: 28rpx;
					color: #333333;
					width: 40%;

					text:nth-of-type(1) {
						color: #FA5E5C;
					}

					text:nth-of-type(2) {
						font-size: 24rpx;
						color: #999999;
					}
				}

				.inp {
					width: 60%;
					text-align: right;
					height: 92rpx;
					line-height: 92rpx;

					input {
						font-size: 28rpx;
						color: #999999;
						height: 92rpx;
						line-height: 92rpx;
					}

					image {
						width: 50rpx;
						height: 50rpx;
						margin-top: 18rpx;
					}
				}

				.xuanze {
					width: 60%;
					text-align: right;
					height: 92rpx;
					line-height: 92rpx;
					color: #368BF8;
				}

				.shangchuan {
					width: 100rpx;
					height: 100rpx;
					margin-left: 74rpx;
				}
			}

			.contentlast {
				border: none;
			}

			.contenttp {
				height: 120rpx;
			}

			.contentdx {

				.name {
					font-size: 28rpx;
					color: #333333;
					width: 90%;
				}

				image {
					width: 40rpx;
					height: 40rpx;
					margin-top: 26rpx;
				}

				.inp {
					width: 40%;
				}

				.xuanze {
					width: 80%;
				}
			}
			
			.contenttext {
				width: 100%;
				height: 200rpx;
				
				textarea{
					width: 100%;
					height: 180rpx;
					font-size: 28rpx;
					color: #333333;
				}
			}
		}

		.form1 {
			margin-top: 20rpx;
		}

		.footer {
			width: 100%;
			margin: 0 auto 40rpx;
			margin-top: 60rpx;
			height: 72rpx;
			text-align: center;

			.submit {
				width: 240rpx;
				height: 72rpx;
				line-height: 72rpx;
				background: linear-gradient(90deg, #65bdfc, #398ef8);
				margin-left: 248rpx;
				border-radius: 36rpx;
				border-top-left-radius: 0;
				border-bottom-left-radius: 42rpx;
				color: #FFFFFF;
				font-size: 32rpx;
			}
		}
	}
</style>